<?php

namespace App\Strategies;

use App\Constants\CreditConstant;
use App\Models\Factory\CreditFactory;
use App\Models\Factory\ProductFactory;
use App\Services\Core\Store\Qiniu\QiniuService;
use App\Strategies\AppStrategy;
use App\Strategies\UserStrategy;
/**
 * 积分公共策略
 *
 * Class UserStrategy
 * @package App\Strategies
 */
class CreditStrategy extends AppStrategy
{
    /**
     * 积分号
     */
    public static function creditNid()
    {
        $nid = date('Y') . date('m') . date('d') . date('H') . date('i') . date('s') . UserStrategy::getRandChar(6);
        return 'credit_' . $nid;
    }

    /**
     * @param array $applyArr
     * 返回产品申请数据
     */
    public static function getProductApply($userId, $applyArr = [])
    {
        $productArr = [];
        //产品信息
        foreach ($applyArr as $key => $val) {
            $product = ProductFactory::getProductLogoAndName($val['product_id']);
            $logObj  = CreditFactory::getCreditProductLog($userId, $val['id']);
            if (!empty($logObj)) {
                $productArr[$key]['apply_sign'] = CreditConstant::SIGN_FULL;
            } else {
                $productArr[$key]['apply_sign'] = CreditConstant::DEFAULT_EMPTY;
            }
            $productArr[$key]['config_id']      = $val['id'];
            $productArr[$key]['config_credits'] = $val['credits'];
            $productArr[$key]['product_id']     = $product['platform_product_id'];
            $productArr[$key]['product_name']   = $product['platform_product_name'];
            $productArr[$key]['product_logo']   = QiniuService::getProductImgs($product['product_logo'], $product['platform_product_id']);
        }
        return $productArr;
    }


}
